package com.touzi.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class BeanUtils {
    public static String serializeBean(Object obj) {
        ObjectMapper objectMapper = new ObjectMapper();
        String result;

        try {
            result = objectMapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            result = null;
        }
        return result;
    }

    public static String serializeBeanGentle(Object obj) {
        ObjectMapper objectMapper = new ObjectMapper();
        String result;

        try {
            result = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            result = null;
        }
        return result;
    }
}
